-*- coding: utf-8 -*-

* Calibre OPDS client
** What's this?
This is a calibre plugin that is an OPDS client intended to read the contents of another calibre installation, find the differences to the current calibre and offer to copy books from the other calibre into the current calibre
** How do I install it?
Requires [[https://git-scm.com/downloads][git]] and [[https://calibre-ebook.com/download][calibre]] installed (minimum calibre version: 6 (because the plugin now uses PyQt6)):
 - Clone the repository:
   #+BEGIN_EXAMPLE
     git clone https://github.com/steinarb/opds-reader.git
   #+END_EXAMPLE
 - Install the plugin in calibre
   #+BEGIN_EXAMPLE
     cd opds-reader/calibre_plugin/
     calibre-customize -b .
   #+END_EXAMPLE
 - Start calibre (if calibre was already running, stop calibre and start it again)
 - Click the button "Preferences"
 - In the dialog "calibre - Preferences":
   - Under "Interface", click on the button "Toolbar"
   - In the dialog "calibre - Preferences - Toolbar":
     - In the dropdown, select "The main toolbar"
     - In "Available actions" scroll down to find "OPDS Client" and select it
     - Click the top arrow button (arrow pointing right)
     - Click the "Apply" button
   - Click the "Close" button
** How do I use it?
I made this tool to backup my book collection between two PCs in my home LAN, and that is the procedure I will document here:
  1. In the calibre you wish to copy from (in this example called calibre1.home.lan):
     1. Click Preferences
     2. In the "calibre - Preferences" dialog:
        1. Click "Sharing over the net"
        2. In the "calibre - Preferences - Sharing over the net" dialog:
           1. Click the "Start Server" button
           2. Select the checkbox "Run server automatically when calibre starts"
           3. Click the "Apply" button
        3. Click the "close" button
  2. In the calibre you wish to copy to
     1. Install this plugin (see the "How do I install it?" section)
     2. Click the "OPDS client" button
     3. In the "OPDS client" dialog
        1. Edit the "OPDS URL" value, change
           : http://localhost:8080/opds
           to
           : http://calibre1.home.lan:8080/opds
           and then press the RETURN key on the keyboard
        2. Click the "Download OPDS" button
        3. Wait until the OPDS feed has finished loading (this may take some time if there is a large number of books to load)
           - Note: if no books appear, try unchecking the "Hide books already in the library" checkbox.  If that makes a lot of books appear, it means that the two calibre instances have the same books
        4. select the books you wish to copy into the current calibre and click the "Download selected books"
           - calibre will start downloading and installing the books:
             - The Jobs counter in calibre's lower right corner, will show a decrementing number and the icon will spin
             - The book list will be updated as the books are downloaded
        5. The downloaded books will be in approximately the same order as in the original, but the time stamp will be the download time. To fix the time stamp, click on the "Fix timestamps of the selection" button
           - The updated timestamps may not show up immediatly, but they will show up after the first update of the display, and the books will be ordered according to the timestamp after stopping and starting calibre
** Troubleshooting
*** Nothing happens when I click on "Download OPDS" and the URL I typed in isn't preserved

Make sure you press Enter after finishing typing into the URL combo box.  This will download the top OPDS catalog for the OPDS feed.

*** How to I debug the plugin

If the plugin doesn't work for some reason, start calibre in debug mode and see what ends up in the console.

To start calibre in debug mode, open a command line window, and type:
#+begin_example
  calibre-debug
#+end_example

If necessary, add "print()" statements to the code to check that its get to the places you expect it to get and start printing out variables.

** License
This calibre plugin is copyright Steinar Bang, 2015-2022, and licensed Under GPL version 3.

See the LICENSE file for more detail.
